require(['./config'], () => {
  require(['jquery', 'artTemplate', 'swiper', 'loadHeaderFooter'], ($, template, Swiper) => {
    // 请求首页加载时的数据
    class Index{
      constructor(){
        this.bannerOne()
        this.bannerTwo()
        this.tab()
        this.getXiongmaoListOne()
        this.getXiongmaoListTwo()
        this.getXiongmaoListThree()
        this.getXiongmaoListFour()
      }
      bannerOne(){
        var mySwiper = new Swiper ('.bannerOne', {
          loop: true, // 循环模式选项
          autoplay:true,
          // 如果需要前进后退按钮
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          },
        })        
      }
      bannerTwo(){
        var mySwiper = new Swiper ('.bannerTwo', {
          loop: true, // 循环模式选项
          autoplay: true,
          // 如果需要分页器
          pagination: {
            el: '.swiper-pagination'
          },
          // 如果需要前进后退按钮
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          },
        })
      }
      tab(){
        $('#tab li').on('click',function(){
          $(this).addClass('ac').siblings().removeClass('ac')
          $('.banner-list').eq($(this).index()).addClass('ac').siblings().removeClass('ac')
        })
      }
      getXiongmaoListOne(){
        $.get('http://www.xiongmaoyouxuan.com/api/search?word=%E9%98%BF%E7%8E%9B%E5%B0%BC%E7%B2%89%E5%BA%95&start=0&sort=0&couponOnly=0&minPrice=0&maxPrice=0',resp=>{
          if(resp.code===200){
            const {list} = resp.data
            // console.log(list.slice(0,8));
            // const {list} = list.slice(0,3)
            const html = template('bannerTemplate', { list:list })
            $('#bannerListOne').html(html)
          }
        })
      }
      getXiongmaoListTwo(){
        $.get('http://www.xiongmaoyouxuan.com/api/search?word=%E9%98%BF%E7%8E%9B%E5%B0%BC&start=0&sort=0&couponOnly=0&minPrice=0&maxPrice=0',resp=>{
          if(resp.code===200){
            // console.log(resp);
            const {list} = resp.data
            // console.log(list);
            const html = template('bannerTemplateTwo', { list:list })
            $('#bannerListTwo').html(html)
          }
        })
      }
      getXiongmaoListThree(){
        $.get('http://www.xiongmaoyouxuan.com/api/search?word=%E9%98%BF%E7%8E%9B%E5%B0%BC%E9%A6%99%E6%B0%B4&start=0&sort=0&couponOnly=0&minPrice=0&maxPrice=0',resp=>{
          if(resp.code===200){
            // console.log(resp);
            const {list} = resp.data
            // console.log(list);
            const html = template('bannerTemplateThree', { list:list })
            $('#bannerListThree').html(html)
          }
        })
      }
      getXiongmaoListFour(){
        $.get('http://www.xiongmaoyouxuan.com/api/search?word=%E9%98%BF%E7%8E%9B%E5%B0%BC%E7%A4%BC%E7%9B%92&start=0&sort=0&couponOnly=0&minPrice=0&maxPrice=0',resp=>{
          if(resp.code===200){
            // console.log(resp);
            let {list} = resp.data
            list = list.slice(3,6)
            // console.log(list);
            const html = template('bannerTemplateFour', { list:list })
            $('#bannerListFour').html(html)
          }
        })
      }
    }
    new Index()
  })
})